package com.yanwq.sayhi.common.tool;

import android.content.Context;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

import com.yanwq.sayhi.MApplication;

/**
 * 作者：yanweiqiang。
 * 日期：2016/6/14 0014。
 */
public class AppTool {

    public static String getDeviceId() {
        TelephonyManager tm = (TelephonyManager) MApplication.getContext().getSystemService(Context.TELEPHONY_SERVICE);
        String deviceId = tm.getDeviceId();

        if (deviceId == null || deviceId.length() == 0) {
            WifiManager manager = (WifiManager) MApplication.getContext().getSystemService(Context.WIFI_SERVICE);
            if (manager != null) {
                deviceId = manager.getConnectionInfo().getMacAddress();
            }
        }

        return deviceId;
    }

    public static String getPhoneNo() {
        TelephonyManager tm = (TelephonyManager) MApplication.getContext().getSystemService(Context.TELEPHONY_SERVICE);
        String phone = tm.getLine1Number();

        if (phone == null) {
            return "";
        }

        return phone;
    }
}
